package com.shitou.shitousearch.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.*;

/**
 * class detail:
 *
 * @author 石头人
 */
@SuppressWarnings("all")
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class SearchRespAttrVo implements Serializable {

    private Long attrId;
    private String attrName;
    private List<String> value;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof SearchRespAttrVo)) return false;
        SearchRespAttrVo that = (SearchRespAttrVo) o;
        boolean equals = Objects.equals(getAttrName(), that.getAttrName());
        if ( equals == true ){
            List<String> value1 = this.getValue();
            List<String> value2 = that.getValue();
            this.setValue(addValue(value1, value2));
        }
        return equals;
    }


    private List<String> addValue(List<String> value1, List<String> value2){
        Set<String> set = new HashSet<>();
        set.addAll(value1);
        set.addAll(value2);
        return new ArrayList<String>(set);
    }


    @Override
    public int hashCode() {
        return Objects.hash(getAttrName());
    }
}
